<?php
require_once 'client/facebook.php';

$appapikey = '83cc71d0dbb650cf0d8af70a0bd053cb';
$appsecret = 'ab118d139d347dbb714c62f6915ef1b9';
$facebook = new Facebook($appapikey, $appsecret);
$facebook->require_frame();
$user = $facebook->require_login();

//[todo: change the following url to your callback url]
$appcallbackurl = 'http://apps.facebook.com/hot_gallery/';  

//catch the exception that gets thrown if the cookie has an invalid session_key in it
try {
  if (!$facebook->api_client->users_isAppAdded()) {
    $facebook->redirect($facebook->get_add_url());
  }
} catch (Exception $ex) {
  //this will clear cookies for your application and redirect them to a login prompt
  $facebook->set_user(null, null);
  $facebook->redirect($appcallbackurl);
}
